-- die_poisoned_user
-- created by dengc
-- 死亡后对玩家施加中毒效果，每回合掉prop[3]%生命值，持续prop[4]轮

return {
    apply = function(prop, baseValue)
        return baseValue;
    end,

    -- 受创触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_MONSTER then
            return false;
        end

        local propId = PropM.getPropId("poisoned");
        local maxHp = ME.user:queryAttrib("max_hp");

        -- 中毒，威力最小为1点
        -- damage = floor * (60 + layerFix) * prop[3] / 60 / 1000，因此反推可得prop[3]
        local floor = DungeonM.currentLayer();
        local dungeonId = DungeonM.getDungeonId();
        if dungeonId == nil then
            dungeonId = ME.user.dbase:query("currentDungeon");
        end
        local layerFix = DungeonAreaM.query(dungeonId,"layer_fix");

        local v = math.modf(maxHp * prop[3] * 60 / floor / (60 + layerFix));
        v = math.max(v, 1);

        local effectRound = CombatM.getRound() + prop[4];
        local arr = ({ propId, 1, v, effectRound, });

        local condition = {
            ["prop"]      = arr,
            ["end_round"] = effectRound,
        }

        -- 附加中毒状态
        CombatStatusM.applyStatus(ME.user, "poisoned", condition);

        return true;
    end,

    record = function(target, prop, path)
        return false;
    end
};
